<template>
  <div>
    <el-page-header @back="goBack" content="指标详情"> </el-page-header>
    <div class="ueba-detail-main">
      <secDescriptions
        :data="formData"
        :colon="true"
        :labelStyle="{ width: '100px', 'text-align': 'right', 'line-height': '30px' }"
        :contentStyle="{ 'line-height': '30px' }"
        :column="3"
        :border="false"
        :keyData="baseInfo"
        title="基础信息"
      >
      </secDescriptions>

      <secDescriptions
        :data="formData"
        :colon="true"
        :labelStyle="{ width: '100px', 'text-align': 'right', 'line-height': '30px' }"
        :contentStyle="{ 'line-height': '30px' }"
        :column="3"
        :border="false"
        :keyData="risk"
        title="风险信息"
      >
      </secDescriptions>
    </div>
  </div>
</template>

<script>
import secDescriptions from "components/descriptions/myDescriptions";
import { getAutoPreConditionsApi } from "api/configApi";

export default {
  components: {
    secDescriptions,
  },
  props: {},
  computed: {},
  data() {
    return {
      formData: {},
      risk: [
        { label: "风险名称", prop: "holeName" },
        {
          label: "风险类型",
          prop: "holeType",
          formatter: (data) => {
            return this.utils.getDicLabel("101002", data.holeType);
          },
        },
        {
          label: "风险等级",
          prop: "riskLevel",
          formatter: (data) => {
            return this.utils.getDicLabel("level", data.riskLevel);
          },
        },
        { label: "风险描述", prop: "holeDetail" },
        { label: "修复建议", prop: "repairRecommend" },
      ],
      baseInfo: [
        { label: "指标名称", prop: "name" },
        {
          label: "指标来源",
          prop: "scene",
          formatter: (data) => {
            let t = "";
            if (Array.isArray(data.scene)) {
              data.scene.forEach((e) => {
                t += this.utils.getDicLabel(101003, e) + ",";
              });
              return t.slice(0, -1);
            }
            return t;
          },
        },
        {
          label: "是否必须",
          prop: "required",
          formatter: (data) => {
            return this.utils.getDicLabel(101004, data.required);
          },
        },
        {
          label: "是否自动化",
          prop: "auto",
          formatter: (data) => {
            return this.utils.getDicLabel(101004, data.auto);
          },
        },
        {
          label: "自动化前置条件",
          prop: "autoPreConditions",
          formatter: (data) => {
            if (!data.autoPreConditions) return "-";
            let autoPerStrs = data.autoPreConditions.split(",");
            if (autoPerStrs && autoPerStrs.length > 0) {
              let autoPerLable = autoPerStrs?.map((item) => {
                console.log(item);
                return this.autoPerConditions.find((list) => list.code == item)?.message;
              });
              return autoPerLable?.join(",");
            }
          },
        },
        {
          label: "是否启用",
          prop: "enable",
          formatter: (data) => {
            return this.utils.getDicLabel(101004, data.enable);
          },
        },
        {
          label: "策略类型",
          prop: "strategyType",
          formatter: (data) => {
            return this.utils.getDicLabel("strategyType", data.strategyType);
          },
        },
        {
          label: "是否人工辅助",
          prop: "manual",
          formatter: (data) => {
            return this.utils.getDicLabel("whetherNum", data.manual);
          },
        },
        {
          type: "radio",
          label: "是否自动发工单",
          prop: "autoAnquan",
          formatter: (data) => {
            return this.utils.getDicLabel("whetherNum", data.autoAnquan);
          },
        },
        { label: "指标权重", prop: "weight" },
        {
          label: "是否上传证据",
          prop: "evidence",
          formatter: (data) => {
            return this.utils.getDicLabel("whetherNum", data.evidence);
          },
        },
        { label: "创建人", prop: "creator" },
        { label: "创建时间", prop: "createTime" },
        { label: "更新人", prop: "operator" },
        { label: "更新时间", prop: "modifyTime", span: 3 },

        { label: "指标要求", prop: "reportItemContent", span: 3 },
        {
          label: "关联场景",
          prop: "linkedScenes",
          span: 3,
          formatter: (data) => {
            let str = "";
            data.linkedScenes &&
              data.linkedScenes.forEach((item) => {
                str += item.name + "，";
              });
            return str.slice(0, -1);
          },
        },
        { label: "备注", prop: "holeName", span: 3 },
        { label: "记分规则", prop: "itemScore", span: 3 },
      ],
    };
  },
  async mounted() {
    await getAutoPreConditionsApi().then((res) => {
      this.autoPerConditions = res.data || [];
    });
    if (this.$route.query.id) {
      this.formData = await this.fatchData(this.$route.query.id);
      this.formData.itemScore =
        this.formData.itemScore &&
        "执行情况：" +
          "是：" +
          this.formData.itemScore.busAccordScore +
          "分 否：" +
          this.formData.itemScore.busNonaccordScore +
          "分，审计结果：" +
          "符合：" +
          this.formData.itemScore.auditAccordScore +
          "分 不符合：" +
          this.formData.itemScore.auditNonaccordScore +
          "分";
    }
  },
  methods: {
    goBack() {
      this.$router.push("/config/index");
    },

    async fatchData(id) {
      let res = await this.$store.dispatch("config/itemGet", { id: id });
      return res.data;
    },
  },
};
</script>
<style lang="scss" scoped>
.check-box {
  margin: 0 0 20px 20px;
}
</style>
